package br.com.vti.sisp_sicrim.antigo.controller.relatorios;

import java.io.FileNotFoundException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import net.sf.jasperreports.engine.JRException;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.interceptor.download.InputStreamDownload;
import br.com.vti.sisp_sicrim.antigo.model.DidCadastro;
import br.com.vti.sisp_sicrim.antigo.util.Relatorios;
import br.com.vti.sisp_sicrim.antigo.util.Sessao;

/**
 * Classe responsavel por encapsular o tratamento e as consistencias da tela
 * Idcpra01Report
 * 
 * @author Incode - Data: mai/2014
 * 
 */
public class Idcpra01Report {
	private String jMaetrunc;
	private String jIdetrunc;
	private int wdata;
	private int jCont;
	private String dataCorrente;
	private String nomeClasse;
	private Long dinideRegger; // DB
	private Integer dinideComuen; // DB
	private String nroPagina;
	private Result result;
	private Sessao sessao;
	private Relatorios report;
	// Classes views
	DidCadastro vwDidcad = new DidCadastro(); // Classes includes

	public Idcpra01Report() throws JRException, ParseException {
		inicializar();
	}

	public Idcpra01Report(Sessao sessao) throws JRException, ParseException {
		this.sessao = sessao;
		inicializar();
	}

	public void inicializar() throws JRException, ParseException {
		report = new Relatorios();
		jMaetrunc = "";
		jIdetrunc = "";
		wdata = 0;
		jCont = 0;
		dataCorrente = new SimpleDateFormat("dd/MM/yyyy").format(Calendar.getInstance().getTime()); // *DATE
		nomeClasse = this.getClass().getSimpleName(); // *PROGRAM
		report.setNumeroRel(1, "C");
		{
			report.setNumeroLinhaRel(1, 1);
			{
				report.adicionaCampo(1, 2, "lit_1_2", "C", "", "  ");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(2, 3);
			{
				report.adicionaCampo(1, 62, "lit_1_62", "C", "", "* GEJUSPC - GERENCIA DA JUSTICA, SEGURANCA PUBLICA E CIDADANIA");
				report.adicionaCampo(110, 8, "lit_110_8", "C", "", "Pagina: ");
				report.adicionaCampo(119, 5, "nroPagina", "S", "Z.ZZ9", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(3, 3);
			{
				report.adicionaCampo(1, 50, "lit_1_50", "C", "", "* STI     - SUBGERENCIA DE TECNOLOGIA DA INFORMCAO");
				report.adicionaCampo(110, 8, "lit_110_8", "C", "", "Data..: ");
				report.adicionaCampo(119, 10, "dataCorrente", "S", "", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(4, 3);
			{
				report.adicionaCampo(1, 47, "lit_1_47", "C", "", "* INSTITUICAO DE IDENTIFICACAO CIVIL E CRIMINAL");
				report.adicionaCampo(110, 8, "lit_110_8", "C", "", "PROGAM: ");
				report.adicionaCampo(119, 8, "nomeClasse", "S", "", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(5, 1);
			{
				report.adicionaCampo(1, 38, "lit_1_38", "C", "", "* RELATORIO DE NOMES DE MAES INVALIDOS");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(6, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "-");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(7, 5);
			{
				report.adicionaCampo(1, 11, "lit_1_11", "C", "", "NOME DA MAE");
				report.adicionaCampo(32, 17, "lit_32_17", "C", "", "NOME DO INDIVIDUO");
				report.adicionaCampo(64, 9, "lit_64_9", "C", "", "REG. GER.");
				report.adicionaCampo(80, 10, "lit_80_10", "C", "", "NASCIMENTO");
				report.adicionaCampo(92, 4, "lit_92_4", "C", "", "MUN.");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(8, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "-");
				report.setFimLinhaRel();
			}
		}
		report.setNumeroRel(2, "D");
		{
			report.setNumeroLinhaRel(1, 5);
			{
				report.adicionaCampo(1, 30, "Jmaetrunc", "X", "", "");
				report.adicionaCampo(32, 30, "Jidetrunc", "X", "", "");
				report.adicionaCampo(64, 13, "Dinideregger", "N", "ZZZZZZZZ9999-9", "");
				report.adicionaCampo(80, 8, "Wdata", "N", "99/99/9999", "");
				report.adicionaCampo(92, 4, "Dinidecomuen", "N", "9999", "");
				report.setFimLinhaRel();
			}
		}
		report.setNumeroRel(3, "D");
		{
			report.setNumeroLinhaRel(1, 5);
			{
				report.adicionaCampo(1, 30, "Jmaetrunc", "X", "", "");
				report.adicionaCampo(32, 30, "Jidetrunc", "X", "", "");
				report.adicionaCampo(64, 13, "Dinideregger", "N", "ZZZZZZZ99999-9", "");
				report.adicionaCampo(80, 8, "Wdata", "N", "99/99/9999", "");
				report.adicionaCampo(92, 4, "Dinidecomuen", "N", "9999", "");
				report.setFimLinhaRel();
			}
		}
		report.setNumeroRel(4, "D");
		{
			report.setNumeroLinhaRel(1, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "-");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(2, 2);
			{
				report.adicionaCampo(1, 25, "lit_1_25", "C", "", "REGISTROS PROCESSADOS  = ");
				report.adicionaCampo(27, 5, "Jcont", "N", "", "");
				report.setFimLinhaRel();
			}
		}
		setDataCorrente(dataCorrente);
		setNomeClasse(nomeClasse);
	}

	public boolean validar() {
		// validar os campos recebidos da tela
		return true;
	}

	public String getJmaetrunc() {
		return jMaetrunc;
	}

	public void setJmaetrunc(String jMaetrunc) throws ParseException {
		this.jMaetrunc = jMaetrunc;
		report.adicionaValorReport("Jmaetrunc", jMaetrunc);
	}

	public String getJidetrunc() {
		return jIdetrunc;
	}

	public void setJidetrunc(String jIdetrunc) throws ParseException {
		this.jIdetrunc = jIdetrunc;
		report.adicionaValorReport("Jidetrunc", jIdetrunc);
	}

	public int getWdata() {
		return wdata;
	}

	public void setWdata(int wdata) throws ParseException {
		this.wdata = wdata;
		report.adicionaValorReport("Wdata", wdata);
	}

	public int getJcont() {
		return jCont;
	}

	public void setJcont(int jCont) throws ParseException {
		this.jCont = jCont;
		report.adicionaValorReport("Jcont", jCont);
	}

	public String getDataCorrente() {
		return dataCorrente;
	}

	public void setDataCorrente(String dataCorrente) throws ParseException {
		this.dataCorrente = dataCorrente;
		report.adicionaValorReport("dataCorrente", dataCorrente);
	}

	public String getNomeClasse() {
		return nomeClasse;
	}

	public void setNomeClasse(String nomeClasse) throws ParseException {
		this.nomeClasse = nomeClasse;
		report.adicionaValorReport("nomeClasse", nomeClasse);
	}

	public void setPageSize(int pagesize) throws JRException {
		report.setPageSize(pagesize);
	}

	public void setLineSize(int linesize) {
		report.setLineSize(linesize);
	}

	public int getPageSize() {
		return report.getPageSize();
	}

	public int getPageLine() {
		return report.getPageLine();
	}

	public void saltaLinhas(int qtdLinhas) throws ParseException, JRException {
		report.saltaLinhas(qtdLinhas);
	}

	public void gravaRelatorio(int nroRel) throws ParseException, JRException {
		setNroPagina(String.valueOf(report.getPageNumber()));
		report.gravaRelatorio(report, nroRel, false);
	}

	public InputStreamDownload imprimir() throws FileNotFoundException, JRException {
		return report.imprimir();
	}

	public Long getDinideRegger() {
		return dinideRegger;
	}

	public void setDinideRegger(Long dinideRegger) throws ParseException {
		this.dinideRegger = dinideRegger;
		report.adicionaValorReport("dinideRegger", dinideRegger);
	}

	public Integer getDinideComuen() {
		return dinideComuen;
	}

	public void setDinideComuen(Integer dinideComuen) throws ParseException {
		this.dinideComuen = dinideComuen;
		report.adicionaValorReport("dinideComuen", dinideComuen);
	}

	public String getNroPagina() {
		return nroPagina;
	}

	public void setNroPagina(String nroPagina) throws ParseException {
		this.nroPagina = nroPagina;
		report.adicionaValorReport("dinideComuen", dinideComuen);
	}

}
